package com.vdong.shardingorder.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vdong.base.model.BaseResult;
import com.vdong.shardingorder.entity.VdGoods;
import com.vdong.shardingorder.service.IVdGoodsService;
import com.vdong.shardingorder.vo.goods.req.AddGoodsReqVO;
import com.vdong.shardingorder.vo.goods.req.ListGoodsReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@Api(value = "商品基本信息", tags = "商品基本信息")
public class GoodsController {

    @Autowired
    private IVdGoodsService goodsService;


    @PostMapping("/goods/add")
    @ApiOperation(value = "添加商品", notes = "添加商品")
    public BaseResult<Boolean> addGoods(@Valid @RequestBody AddGoodsReqVO req) {
        log.info("添加商品:{}", JSONUtil.toJsonStr(req));
        Boolean bool = goodsService.addGoods(req);
        return new BaseResult<>().data(bool);
    }

    @PostMapping("/goods/list")
    @ApiOperation(value = "商品列表", notes = "商品列表")
    public BaseResult<Boolean> listGoods(@Valid @RequestBody ListGoodsReqVO req) {
        log.info("商品列表:{}", JSONUtil.toJsonStr(req));
        IPage<VdGoods> page = goodsService.listGoods(req);
        return new BaseResult<>().data(page);
    }

}
